<template>
  <div class="page-container">
    <ex_super_table_page v-bind="option" ref="SuperTablePage">
    </ex_super_table_page>
  </div>
</template>

<script>
let emitKey = 'overseas>wms_reorg_order_manage'
import superTablePageFunction from '@/mixin/super-table-page-function';
import emitOnFunction from '@/mixin/emit-on-function';
const status_color_class = {
  CANCELLED: "color_info",
  WAIT_REORG: "color_primary",
  REORGING: "color_primary",
  REORG_EXCEPTION: "color_danger",
  COMPLETED: "color_success",

}
export default {
  title: "title_reorg_manage",
  mixins: [superTablePageFunction, emitOnFunction(emitKey)],
  data() {
    return {

      option: {
        search: {
          model: [
            { label: "label_reorg_code", key: "orderNo", type: 'input', },//
            {
              label: "label_reorg_type", key: "type", type: 'select',//
              enum: 'ReorgOrderTypeEnum',
            },
            {
              label: "label_status", key: "status", type: 'select',//
              enum: 'ReorgOrderStatusEnum',
            },
            { label: "label_create_user", key: "creator", type: 'input', },//
            {
              label: "label_start_time",
              key: "createDateStart",
              fold: true,
              type: 'date-picker',
              attrs: { type: "datetime" },
            },
            {
              label: "label_end_time",
              key: "createDateEnd",
              fold: true,
              type: 'date-picker',
              attrs: { type: "datetime" },
            },

            //所有元素均可添加可选attrs对象增加属性，详细属性列表由element-ui提供
          ],
        },
        actionExtra: [
          { label: 'label_new', attrs: { type: "primary" }, auth: 'wms_reorg_order_manage_edit', click: this.clickAdd },
          // { label: 'label_import', attrs: { type: "primary" }, click: this.$noFunction },
          // { label: 'label_export', attrs: { type: "primary" }, click: this.$noFunction },
        ],
        action: [
        ],

        table: {
          url: "/wms-api/inside/ReorgOrderRpc/selectPage.json",
          attrs: {},
          model: [
            { key: 'orderNo', label: 'label_reorg_code', 'min-width': 160, },
            { key: 'bizType', label: 'label_business_type', 'width': 120, formatter: (r, c, v) => this.$enumShow(v, "BizTypeEnum") },

            { key: 'type', label: 'label_fms_service_code_type', 'width': 120, formatter: (r, c, v, i) => this.$enumShow(v, "ReorgOrderTypeEnum"), },
            {
              key: 'status', label: 'label_status', 'width': 120, render: (h, { row, column }) => {
                const value = row[column.property]
                const r = this.$enumShow(value, "ReorgOrderStatusEnum")
                return (<span class={status_color_class[value]}>{r}</span>)
              }
            },
            { key: 'createClient', label: 'label_Create_Source', 'width': 110, formatter: (r, c, v, i) => this.$enumShow(v, "ReorgCreateClientEnum"), },
            { key: 'remark', label: 'label_remark', 'min-width': 120, 'show-overflow-tooltip': true, },

            { key: 'totalNum', label: 'label_plan_reorg_sum_count', 'width': 110, },
            { key: 'waitMoveOutNum', label: 'label_wait_take_down_count', 'width': 110, },
            { key: 'waitMoveInNum', label: 'label_wait_put_count', 'width': 110, },
            { key: 'actualMoveOutNum', label: 'label_actual_reorg_out_count', 'width': 110, },
            { key: 'actualMoveInNum', label: 'label_actual_reorg_in_count', 'width': 110, },

            { key: 'creator', label: 'label_create_user', 'width': 120, },
            { key: 'gmtCreate', label: 'label_create_time', 'width': 130, 'show-overflow-tooltip': true, formatter: (r, c, v, i) => this.$dateFormat(v) },
            {
              type: 'operate', width: 210, fixed: "right", operate: [

                { label: 'label_view_detail', click: (row) => this.clickDetail(row) },
                {
                  type: 'more',
                  items: [
                    {
                      label: 'label_reorg_take', auth: 'wms_reorg_order_manage_operate',
                      disabled: (row) => ['CANCELLED', 'COMPLETED'].includes(row.status) || row.waitMoveOutNum <= 0 && row.waitMoveInNum <= 0,
                      click: (row) => this.clickOperate(row, 'TAKE_DOWN' ),
                    },
                    {
                      label: 'label_reorg_put', auth: 'wms_reorg_order_manage_operate',
                      disabled: (row) => ['CANCELLED', 'COMPLETED'].includes(row.status) || row.waitMoveOutNum <= 0 && row.waitMoveInNum <= 0,
                      click: (row) => this.clickOperate(row, 'PUT_AWAY'),
                    },
                    {
                      label: 'label_reorg_confirm', auth: 'wms_reorg_order_manage_confirm',
                      disabled: (row) => row.status == 'CANCELLED' || row.status == 'WAIT_REORG' || row.status == 'REORGING' || row.status == 'COMPLETED',
                      click: (row) => this.completeResult(row)
                    }
                  ]
                },
                {
                  label: 'label_cancel', auth: 'wms_reorg_order_manage_cancel', type: "confirm-button", if: (row) => ["WAIT_REORG"].includes(row.status),
                  url: '/wms-api/inside/ReorgOrderRpc/cancel.json',
                  message: 'text_confirm_sure_cancel_order',
                  buttonClass: "button_text_danger", confirmButtonType: 'danger',
                  params: (row) => { return { "id": row["id"] } }, done: ['reload', 'tip']
                },
                // {
                //   label: '删除', type: "confirm-button", url: '/wms-api/inside/ReorgOrderRpc/delete.json', message: '确定要该调整单？',
                //   buttonClass: "button_text_danger", confirmButtonType: 'danger',
                //   params: (row) => { return { "id": row["id"] } }, done: ['reload', 'tip']
                // },
              ]
            },
          ],
        },
      },
    };
  },
  methods: {
    clickOperate(row, type) {
      this.$router.push({ path: '/page/wms/inside/reorg_operate', query: { id: row.id, code: row.orderNo, type, emitKey } })
    },
    clickDetail(row) {
      this.$router.push({ path: '/page/wms/inside/reorg_detail', query: { id: row.id, emitKey } })
    },
    clickAdd() {
      this.$router.push({ path: '/page/wms/inside/reorg_create', query: { emitKey } })
    },
    completeResult(row) {
      this.$confirm(this.$tt('label_reorg_confirm'), this.$tt('label_tip'), {
        confirmButtonText: this.$tt('label_confirm'),
        cancelButtonText: this.$tt('label_cancel'),
        type: 'warning'
      }).then(() => {
        this.$ajax({
          url: "/wms-api/inside/ReorgOrderRpc/confirmOrder.json",
          method: 'post',
          data: { id: row.id },
          success: (res) => {
            this.$message.success(this.$tt('tip_submit_success'))
            this.reload()
          },
        })
      }).catch(() => {

      });


    }
  }
}
</script>

<style scoped></style>
